/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.colswedev.app.labhudson.view;

import javax.swing.JOptionPane;
import org.colswedev.app.labhudson.control.TransactionControl;

/**
 *
 * @author Leonardo Bohórquez
 */
public class pnlWithdraw extends javax.swing.JPanel {

    /**
     * Creates new form pnlWithdraw
     */
    public pnlWithdraw() {
	initComponents();
	txtAmount.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT
     * modify this code. The content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        radgGroup = new javax.swing.ButtonGroup();
        rad50 = new javax.swing.JRadioButton();
        rad100 = new javax.swing.JRadioButton();
        rad400 = new javax.swing.JRadioButton();
        rad200 = new javax.swing.JRadioButton();
        rad300 = new javax.swing.JRadioButton();
        radCustomAm = new javax.swing.JRadioButton();
        txtAmount = new javax.swing.JTextField();
        cmdOK = new javax.swing.JButton();
        cmdCancel = new javax.swing.JButton();

        radgGroup.add(rad50);
        rad50.setText("$50.000");

        radgGroup.add(rad100);
        rad100.setText("$100.000");

        radgGroup.add(rad400);
        rad400.setText("$400.000");

        radgGroup.add(rad200);
        rad200.setText("$200.000");

        radgGroup.add(rad300);
        rad300.setText("$300.000");

        radgGroup.add(radCustomAm);
        radCustomAm.setText("Cantidad personalizada");

        txtAmount.setEditable(false);

        cmdOK.setText("Aceptar");
        cmdOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdOKActionPerformed(evt);
            }
        });

        cmdCancel.setText("Cancelar");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rad100)
                            .addComponent(rad200)
                            .addComponent(rad50))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 95, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(rad300)
                                .addContainerGap())
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(radCustomAm)
                                    .addComponent(rad400))
                                .addGap(87, 87, 87))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addComponent(txtAmount, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cmdOK)
                        .addGap(18, 18, 18)
                        .addComponent(cmdCancel)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(78, 78, 78)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rad50)
                    .addComponent(rad300))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rad100)
                    .addComponent(rad400))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rad200)
                    .addComponent(radCustomAm))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtAmount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 91, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdOK)
                    .addComponent(cmdCancel))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cmdOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdOKActionPerformed
	Double amount;
	boolean flag = true;
	if (radgGroup.isSelected(rad50.getModel())) {
	    amount = 50000.;
	} else if (radgGroup.isSelected(rad100.getModel())) {
	    amount = 100000.;
	} else if (radgGroup.isSelected(rad200.getModel())) {
	    amount = 200000.;
	} else if (radgGroup.isSelected(rad300.getModel())) {
	    amount = 300000.;
	} else if (radgGroup.isSelected(rad400.getModel())) {
	    amount = 400000.;
	} else if (radgGroup.isSelected(radCustomAm.getModel())) {
	    try {
		amount = Double.parseDouble(txtAmount.getText());
	    } catch (NumberFormatException e) {
		flag = false;
		JOptionPane.showMessageDialog(null, "Por favor solo escriba numeros", "Error",
			JOptionPane.ERROR_MESSAGE);
	    }
	}
	if (flag) {
	    int opt = JOptionPane.showConfirmDialog(null, "Usted va a retirar $" + txtAmount.getText()
		    + "\nConfirme si desea aceptar", "Confirmar la transacción",
		    JOptionPane.YES_NO_OPTION, JOptionPane.OK_CANCEL_OPTION);
	    switch(opt){
		case 0:
		    //TransactionControl.getInstance().
	    }
	}

    }//GEN-LAST:event_cmdOKActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cmdCancel;
    private javax.swing.JButton cmdOK;
    private javax.swing.JRadioButton rad100;
    private javax.swing.JRadioButton rad200;
    private javax.swing.JRadioButton rad300;
    private javax.swing.JRadioButton rad400;
    private javax.swing.JRadioButton rad50;
    private javax.swing.JRadioButton radCustomAm;
    private javax.swing.ButtonGroup radgGroup;
    private javax.swing.JTextField txtAmount;
    // End of variables declaration//GEN-END:variables
}
